package routers

import (
	"MaternalBaby/api/controllers"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/cors"
)

func init() {
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "X-Requested-With"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin"},
		AllowCredentials: true,
	}))
	ns := beego.NewNamespace("/v1",
		beego.NSNamespace("/feedback", beego.NSInclude(&controllers.Feedback{})),
		beego.NSNamespace("/person", beego.NSInclude(&controllers.Person{})),
		beego.NSNamespace("/record", beego.NSInclude(&controllers.Record{})),
		beego.NSNamespace("/user", beego.NSInclude(&controllers.User{})),
	)
	beego.AddNamespace(ns)

	beego.Router("/callback", &controllers.MainController{}, "*:Callback")
	beego.Router("/admin", &controllers.MainController{}, "*:Admin")
	beego.Router("/update", &controllers.MainController{}, "*:Update")
	beego.Router("/*", &controllers.MainController{})
}
